<?php


namespace App\Http\Controllers\Drivers\V2\City;


use App\Http\Controllers\Controller;
use App\Models\Drivers;
use App\Services\CityService;
use App\Services\RedisOperation;
use App\Services\ServiceCity;
use Illuminate\Http\Request;

class CityController extends Controller
{
    /**
     * 城市列表
     */
     public function lists(Request $request)
      {
        $city = new CityService();
        $lat  = (string) $request->post('lat');
        $lng  = (string) $request->post('lng');
        $ret  = $city->getList($lat,$lng);
        return $this->sendJson($ret);
      }
    /**
     * 开放的接单城市
     */
      public function service_city(Request $request ,ServiceCity $serviceCity)
      {
          $lists = $serviceCity->getList();
         return  $this->sendJson($lists);
      }

    /**
     * @param Request $request
     * @return CityController|\Illuminate\Http\JsonResponse
     * @throws \Exception
     * 缓存当前城市所有司机ID
     */
      public function set_id(Request $request)
      {
          $city = (int)$request->post('city'); //获取当前城市的city值
          $drivers_id = Drivers::query()->where(['city'=>$city,'status'=>2])->get(['id']);
          RedisOperation::set('driverid',json_encode($drivers_id)); //缓存当前城市的所有司机Id
         return $this->sendSuccess('ok');
      }
}